package concurrency.chapter6;

public class ThreadCloseGraceful {
    private static class Worker extends Thread{

        private volatile boolean start = true;
        @Override
        public void run() {
            while (start){

            }
        }
        //通过设置开关来控制线程结束
        public void shutdown(){
            this.start = false;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Worker worker=new Worker();
        worker.start();
        Thread.sleep(4000);
        worker.shutdown();
    }

}
